package top.yueyazhui.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.yueyazhui.business.service.BusinessService;
import top.yueyazhui.common.bean.Response;

@RestController
@RequestMapping("/business")
public class BusinessController {

    @Autowired
    BusinessService businessService;

    @PostMapping("/purchase")
    public Response purchase(@RequestParam("userId") String userId, @RequestParam("commodityCode") String commodityCode, @RequestParam("count") Integer count, @RequestParam("money") Double money) {
        try {
            businessService.purchase(userId, commodityCode, count, money);
            return Response.success("下单成功");
        } catch (Exception e) {
            return Response.error("下单失败", e.getMessage());
        }
    }
}
